<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>定时函数</title>
		<script>
			var timer;
			function showTime(){
				document.getElementById("time").innerHTML=new Date().toLocaleString();
			}
			window.onload=showTime;
			
			timer=window.setInterval(showTime,1000);
			
			function stopTime(){
				window.clearInterval(timer);
			}
			function clearBody(){
				document.body.innerHTML="";
			}
		</script>
	</head>
	<!-- -onload="showTime()" -->
	<body> 
		<h1 id="time"></h1>
		<button type="button" onclick="stopTime()">停止计时</button>
		<button type="button" onclick="clearBody()">清除网页</button>
	</body>
</html>